#ifndef IMAGE_H_INCLUDED
#define IMAGE_H_INCLUDED

#include "log.h"
#include <cstdlib>

class I_Point
{
public:
	I_Point(int _x = 0, int _y = 0);	
	int x, y;
	int type;
	int color[3];
};

class I_Rect
{
public:
	I_Rect(int _x = 0, int _y = 0, int _width = 0, int _height = 0);
	int x, y;
	int width, height;
	int type;
	int color[3];
	
	void SetColor(int r,int g,int b){color[0]=r;color[1]=g;color[2]=b;}
	bool IsInside(I_Point point){if((point.x>x-width/2)&&(point.x < x+width/2)&&(point.y>y-height/2)&&(point.y<y+height/2))return true;return false;}
};

class Image
{
public:
	enum Channel{C1,C2,C3};
	enum Change_Type{Default, RGB2GRAY, GRAY2RGB, RGB2BGR};
	
	Image();
	Image(unsigned int _width, unsigned int _height, unsigned int _channel = 3, unsigned char* _data = 0);
	Image(const Image &src, I_Rect rect);
	unsigned char* data;
	int width, height;
	int widthStep;
	Channel channel;
	
	inline unsigned char* operator[](const int rowIndx){return (data + rowIndx * widthStep);}
	void Release();
	bool Check(const Image &src, const Image &dst) const;
	void CopyTo(Image &dst, const Image &mask = Image()) const;
	void Convert(Image &dst, Change_Type type = Default) const;

	
	// Draw points or rect
	void Draw(I_Point point, int size = 1);
	void Draw(I_Point point, int size, int color[3]);
	void Draw(I_Point point1, I_Point point2);
	void Draw(I_Rect box);
};

void swap(Image &img1, Image &img2);
#endif // IMAGE_H_INCLUDED
